<script>
import GlobalFilterListener from './GlobalFilterListener.vue'
import { formatNumber } from '@/utils'
import { selectEnterpriseTagCodeList } from '@/api/indicator'
export default {
  name: 'monitor-statistics',
  mixins: [GlobalFilterListener],
  data () {
    return {
      type: '1',
      typeValue: '-1',

      count2: 0,
      count3: 0,
    }
  },
  computed: {
    enterpriseList () {
      const lists = this.$store.state.energyEnterpriseList
      const { type, typeValue } = this
      return lists.filter(v => {
        return typeValue === '-1' ||
          (type === '1' && v.districtBelong === typeValue) ||
          (type === '2' && v.belongIndustry === typeValue)
      })
    },
    count1 () {
      return this.enterpriseList.length
    },
    ids () {
      return this.enterpriseList.map(v => Number(v.id))
    },
  },
  watch: {
    ids (val) {
      selectEnterpriseTagCodeList(val).then(res => {
        res.data = res.data || {}
        this.count2 = res.data.indicatorNumber || 0
        this.count3 = formatNumber(res.data.tagCodeNumber || 0)
      })
    }
  },
  mounted () {
    this.$store.dispatch('GET_ENTERPRISE_LIST')
    if (this.ids && this.ids.length) {
      selectEnterpriseTagCodeList(this.ids).then(res => {
        res.data = res.data || {}
        this.count2 = res.data.indicatorNumber || 0
        this.count3 = formatNumber(res.data.tagCodeNumber || 0)
      })
    }
  },
  methods: {
    eventBusHandler ({ type, typeValue }) {
      this.type = type
      this.typeValue = typeValue
    },
  },
}
</script>

<template>
  <div class="monitor-statistics">
    <div class="monitor-item">
      <p class="text">监控企业数</p>
      <p class="number">{{count1}}</p>
    </div>
    <div class="monitor-item">
      <p class="text">监控点数</p>
      <p class="number">{{count2}}</p>
    </div>
    <div class="monitor-item">
      <p class="text">监控数据数</p>
      <p class="number">{{count3}}</p>
    </div>
  </div>
</template>

<style scoped>
.text,.number {
  margin: 0;
  line-height: 1.6;
}
</style>
